package com.longblog.web.dao.user;

import com.longblog.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class UserDao {

    @Autowired
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    /**
     * 根据用户名查询用户信息
     * @author  lilonglong
     * @date 2019/10/8 18:39
     */
    public List<UserVO> getUserByUserName(String userName){
        String sql = "select * from t_user where user_name=:userName";
        Map<String,String> param = new HashMap<>();
        param.put("userName",userName);
        List<UserVO> user = namedParameterJdbcTemplate.query(sql, param, new BeanPropertyRowMapper<UserVO>(UserVO.class));
        return user;
    }
}
